<template>
	<view class="box">
		<view class="top_box">
			<view class="box1 ding">
				<view class="left">收货人</view>
				<view class="right"><input v-model="params.deliveryRecipientName" type="text" placeholder="请输入收货人姓名" />
				</view>
			</view>
			<view class="box1 ding">
				<view class="left">收货电话</view>
				<view class="right">
					<input v-model="params.deliveryRecipientPhone" type="number" maxlength="11" placeholder="请输入电话" />
			</view>
			</view>
			<view class="box1 ding">
				<view class="left">所在地区</view>
				<view class="right" @click="address">{{addressl ? addressl :'请选择省市区'}}<uni-icons
						type="right"></uni-icons></view>
			</view>
			<liu-customize-sel :address="ADS" class="tanchudizhi" ref="scroll"
				@change='chooseSuccess'></liu-customize-sel>
			<view class="box1 ding">
				<view class="left">详细地址</view>
				<view class="right"><input type="text" v-model="params.deliveryAddress" placeholder="请输入详细地址" /></view>
			</view>
		</view>
		<view class="btns">
			<view class="dibu" @click="queren">
				提交修改
			</view>
		</view>
	</view>
</template>

<script>
	import {
		setorderlist
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				params: {
					id:'',
					deliveryRecipientName: '',
					deliveryRecipientPhone: '',
					deliveryProvince: '',
					deliveryCity: '',
					deliveryCounty: '',
					deliveryAddress: '',
				},
				addressl: '',
				ADS: ''
			}
		},

		onLoad(option) {
			const datas = JSON.parse(decodeURIComponent(option.item))
			this.params.id = datas.id
			this.params.deliveryRecipientName = datas.deliveryRecipientName
			this.params.deliveryRecipientPhone = datas.deliveryRecipientPhone
			this.params.deliveryProvince = datas.deliveryProvince
			this.params.deliveryCity = datas.deliveryCity
			this.params.deliveryCounty = datas.deliveryCounty
			this.params.deliveryAddress = datas.deliveryAddress
			this.addressl = datas.deliveryProvince+ datas.deliveryCity+ datas.deliveryCounty
		},
		methods: {
			queren() {
				if(this.params.deliveryRecipientName == '') {
					uni.showToast({
						icon: 'error',
						title: '收货人不能为空'
					})

				}else if(this.params.deliveryRecipientPhone == '') {
					uni.showToast({
						icon: 'error',
						title: '电话不能为空'
					})

				}else if(!/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/.test(this.params
						.deliveryRecipientPhone)) {
					uni.showToast({
						icon: 'error',
						title: '手机号格式不对'
					})

				}else if(this.addressl == '') {
					uni.showToast({
						icon: 'error',
						title: '请选择地址'
					})

				}else if(this.params.deliveryAddress == '') {
					uni.showToast({
						icon: 'error',
						title: '请输入详细地址'
					})
				}else{
					setorderlist(this.params).then(res=>{
						console.log(res);
						uni.navigateBack()
					})
				}
			},
			address() {
				this.$refs.scroll.open()
			},
			//地址选择成功
			chooseSuccess(e) {
				if (e.value == 0) {
					this.addressl = ''
					this.ADS = ''
					this.params.deliveryProvince = ''
					this.params.deliveryCity = ''
					this.params.deliveryCounty = ''
				} else {
					this.addressl = e.value[0].label + e.value[1].label + e.value[2].label
					this.ADS = e.value[2].label
					this.params.deliveryProvince = e.value[0].label
					this.params.deliveryCity = e.value[1].label
					this.params.deliveryCounty = e.value[2].label
				}
			},
		}
	}
</script>

<style lang="scss" scoped>


	.btns {
		width: 90%;
		position: fixed;
		bottom: 0%;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		text-align: center;
	}
	.dibu {
		height: 100rpx;
		background: linear-gradient(84deg, #24180D 0%, #594629 100%);
		border-radius: 43rpx;
		color: #fff;
		text-align: center;
		line-height: 100rpx;

	}

	input {
		font-size: 28rpx;
		text-align: right;
	}

	.ding {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.top_box {
		width: 650rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 20rpx;
		margin-top: 20rpx;

		.left {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #0A0A0A;
		}

		.right {
			font-size: 28rpx;
			font-weight: 500;
		}

		.box1 {
			height: 100rpx;
		}
	}





	.tanchu {
		background-color: #FFFFFF;
		border-radius: 30rpx 30rpx 0rpx 0rpx;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		button {
			width: 677rpx;
			height: 80rpx;
			background: linear-gradient(84deg, #24180D 0%, #594629 100%);
			border-radius: 40rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			font-size: 28rpx;
			color: #FFFFFF;
			line-height: 33rpx;
			margin-top: 100rpx;
		}

		.hezi {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 20rpx;
			padding-bottom: 20rpx;
			border-bottom: 1rpx solid #EEEEEE;

			.left {
				display: flex;
				align-items: center;

				span {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #070707;
					line-height: 33rpx;
				}

				p {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					line-height: 33rpx;
					margin-top: 10rpx;
				}

				image {
					margin-left: 25rpx;
					margin-right: 20rpx;
				}
			}

			.right {
				margin-right: 20rpx;
			}

			image {
				width: 35rpx;
				height: 35rpx;
			}
		}

		.top {
			width: 100%;
			border-bottom: 1px solid #EEEEEE;
			display: flex;
			align-items: center;

			.wenzi {
				width: 90%;
				height: 100rpx;
				text-align: center;
				font-family: Source Han Sans CN;
				font-weight: 400;
				font-size: 30rpx;
				color: #070707;
				line-height: 100rpx;
				// margin-left: -10%;
			}
		}
	}

	.tanchudizhi {
		position: absolute;
		bottom: 0;
		width: 100%;
		background: #ffff;
		left: 0;
		border-radius: 24px 24px 0 0;
	}
</style>